from whiff.middleware import misc
import amLine

class myChart(misc.utility):
    def __call__(self, env, start_response):
        height = 200
        width = 700
        settings = {
            "legend.spacing": 2,
            "legend.text_size": 9,
            "values.x.frequency": 2,
            "values.y.frequency": 2,
            "decimals_separator": ".",
            "values.x.rotate": 45
            }
        labels = [
            { "y":20, "align":"center", "width":width, "text_color": "#505000", "text_size": 15,
              "text": "GDP percent change (line chart)" },
            { "y":height-20, "align":"right", "width":width, "text_color": "#5050FF", "text_size": 12,
              "text": "<![CDATA[ <u><a href='http://www.oecd.org'>OECD.org</a></u>]]>" }
            ]
        series = [ "03 Q3", "03 Q4", "04 Q1", "04 Q2", "04 Q3", "04 Q4", 
                   "05 Q1", "05 Q2", "05 Q3" ]
        graphs = [
            {"title": "Canada", "values": [0.3, 0.9, 0.6, 1.2, 0.9,0.5,0.5,0.8,0.9]},
            {"title": "Mexico", "values": [0.3,1.1,1.4,1.3,0.8,1.3,0.2,-0.3,2.1],
             "bullet": "square", "line_width":2},
            {"title": "United States", "values": [1.8,0.9,1.0,0.9,1.0,0.8,0.9,0.8,1.0]}
            ]
        chartApp = amLine.__middleware__(width=width, height=height,
            labels=labels, series=series, graphs=graphs, settings=settings)
        return self.deliver_page(chartApp, env, start_response)

__middleware__ = myChart
